<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\Goods;
use DB;

class CatController extends Controller
{
    /**
     * Display a listing of the resource.
     *全网搜索
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $goods_name = $request->input('goods_name');
        $goods = DB::table('goods')
                    ->where('goods_name','like',"%{$goods_name}%")
                    ->where('status',1)
                    ->paginate(8);
        return view('home.cat_show')->with('goods',$goods); 
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
       
    }

    /**
     * Display the specified resource.
     *查询栏目下面对应的商品 商品状态为上架
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $goods = Goods::select('goods_id','goods_name','shop_price','sold_number','pic')
                        ->where('cat_id',$id)
                        ->where('status',1)
                        ->paginate(4);
        return view('home.cat_show')->with('goods',$goods);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
